
import django.utils.timezone as timezone
from django.db import models
# Create your models here.

class DB_net_work(models.Model):
    apin_ame=models.CharField(max_length=20, null=True ,verbose_name='接口名字')
    api_url=models.CharField(max_length=20, null=True ,verbose_name='接口地址')
    api_text=models.CharField(max_length=20, null=True ,verbose_name='接口内容')
    def __str__(self):
        return self.apin_ame
# 公告表
class DB_notice(models.Model):
    to_user_id= models.IntegerField(default=0)
    from_user_id=models.IntegerField(default=0)
    content=models.CharField(max_length=100,default='0')
    date=models.CharField(max_length=500,null=True,verbose_name='广播内容')
    def __str__(self):
        return self.content
# 项目表
class DB_project_list(models.Model):
    create_time = models.CharField(max_length=30,null=True,blank=True,default='-')
    name = models.CharField(max_length=50,null=True,blank=True,default='-')
    des = models.CharField(max_length=500,null=True,blank=True,default='-')
    creater = models.CharField(max_length=500,null=True,blank=True,default='')
    # mock = models.CharField(max_length=50,null=True,blank=True,default='mock_data') # mock_data or redirect
    private = models.BooleanField(default=False) # 私密项目
    # power = models.CharField(max_length=500,null=True,blank=True,default='[]') # 权限:  自己，领导，同事，所有人
    Line = models.CharField(max_length=50,null=True,blank=True,default='') # 业务线: app  web
    # P_data = models.CharField(max_length=500,null=True,blank=True,default='') # 公共变量
    # L_data = models.CharField(max_length=500,null=True,blank=True,default='') # 登录状态变量
    dck = models.CharField(max_length=500,null=True,blank=True,default='')
    deleted = models.BooleanField(default=False) #假删除
    Email_to=models.CharField(max_length=50,null=True,blank=True,default='[]')
    # sql
    Sql_host=models.CharField(max_length=50,null=True,blank=True,default='')
    Sql_port=models.IntegerField(default='3306')
    Sql_user=models.CharField(max_length=50,null=True,blank=True,default='')
    Sql_pwd=models.CharField(max_length=50,null=True,blank=True,default='')
    Sql_name=models.CharField(max_length=20,null=True,blank=True,default='')
    #
    doing_api=models.CharField(max_length=50,null=True,blank=True,default='')
    end_result=models.TextField(default='-')
    choser_confing=models.CharField(max_length=50,null=True,blank=True,default='-',verbose_name='')

    def __str__(self):
        return self.name
# 环境表
class DB_env_list(models.Model):
    host=models.CharField(max_length=100,null=True,blank=True,default='http://')
    type=models.CharField(max_length=100,null=True,blank=True,default='-')
    des=models.CharField(max_length=100,null=True,blank=True,default='-')
    def __str__(self):
        return self.host
# 接口商店表
class DB_Api_list(models.Model):
    project_id=models.CharField(max_length=100, null=True, blank=True, default='')  # 接口名字
    name = models.CharField(max_length=100, null=True, blank=True, default='')  # 接口名字
    create_time= models.CharField(max_length=15, null=True, blank=True, default='')
    host = models.CharField(max_length=100, null=True, blank=True, default='')  # 域名
    path = models.CharField(max_length=100, null=True, blank=True, default='')  # url路径
    method = models.CharField(max_length=100, null=True, blank=True, default='')  # 请求方式
    params = models.CharField(max_length=100, null=True, blank=True, default='')  # url中的参数
    headers = models.CharField(max_length=100, null=True, blank=True, default='')  # 请求头
    des = models.CharField(max_length=100, null=True, blank=True, default='')  # 接口描述
    payload_method = models.CharField(max_length=30, null=True, blank=True, default='')
    payload_fd = models.CharField(max_length=3000, null=True, blank=True, default='[]')
    payload_xwfu = models.CharField(max_length=3000, null=True, blank=True, default='[]')
    payload_raw_method = models.CharField(max_length=30, null=True, blank=True, default='')
    payload_raw = models.CharField(max_length=3000, null=True, blank=True, default='')
    payload_GQL_q = models.CharField(max_length=3000, null=True, blank=True, default='')
    payload_GQL_g = models.CharField(max_length=3000, null=True, blank=True, default='')
    binary_file = models.CharField(max_length=300, null=True, blank=True, default='', verbose_name='接口文件')
    def __str__(self):
        return self.name

# 权限管理
class DB_power(models.Model):
    power_name=models.CharField(max_length=100, null=True, blank=True, default='-')
    users = models.CharField(max_length=500, null=True, blank=True, default='[]')  # 所拥有权限的用户
    power_path = models.CharField(max_length=30, null=True, blank=True, default='-')
    def __str__(self):
        return self.power_name

# 用例管理设置
class DB_case_set(models.Model):
    create_time = models.CharField(max_length=30,null=True,blank=True)
    project_id=models.IntegerField(default=0)
    name=models.CharField(max_length=10,null=True,blank=True,default='新接口')
    label=models.CharField(max_length=10,null=True,blank=True,default='新接口')
    type=models.CharField(max_length=100,null=True,blank=True,default='api')
    # do_time=models.CharField(max_length=5000,null=True,blank=True,default= '')
    children = models.CharField(max_length=5000,null=True,blank=True,default='[]')
    des = models.CharField(max_length=300, null=True, blank=True, default='')
    host = models.CharField(max_length=300, null=True, blank=True, default='')
    path = models.CharField(max_length=300, null=True, blank=True, default='')
    method = models.CharField(max_length=30, null=True, blank=True, default='')
    params = models.CharField(max_length=3000, null=True, blank=True, default='[]')
    headers = models.CharField(max_length=3000, null=True, blank=True, default='[]')
    payload_method = models.CharField(max_length=30, null=True, blank=True, default='')
    payload_fd = models.CharField(max_length=3000, null=True, blank=True, default='[]')
    payload_xwfu = models.CharField(max_length=3000, null=True, blank=True, default='[]')
    payload_raw_method = models.CharField(max_length=30, null=True, blank=True, default='')
    payload_raw = models.CharField(max_length=3000, null=True, blank=True, default='')
    payload_GQL_q = models.CharField(max_length=3000, null=True, blank=True, default='')
    payload_GQL_g = models.CharField(max_length=3000, null=True, blank=True, default='')
    binary_file=models.CharField(max_length=300, null=True, blank=True, default='',verbose_name='接口文件')
    def __str__(self):
        return self.label

class DB_report(models.Model):
    pro_ject_id = models.CharField(max_length=10,null=True,blank=True,default='') #所属项目id
    create_time = models.CharField(max_length=15,null=True,blank=True,default='') #所属项目id
    all_result = models.BooleanField(default=True) #最终结果
    apis_result = models.TextField(default='[]') #详细接口结果
    def __str__(self):
        return self.create_time

class DB_monitor(models.Model):
    label = models.CharField(max_length=100,default='',null=True,blank=True)
    pro_ject_id = models.CharField(max_length=10,default='',null=True,blank=True)
    method = models.CharField(max_length=10,default='',null=True,blank=True) # 间隔时间 ， 每日定时，接口触发，jenkins语法
    value  = models.CharField(max_length=100,default='',null=True,blank=True)
    status = models.BooleanField(default=False) #开关状态
    step =  models.CharField(max_length=100,default='',null=True,blank=True)
    email =  models.CharField(max_length=100,default='',null=True,blank=True)
    robot =   models.CharField(max_length=100,default='',null=True,blank=True) #机器人接口 ，钉钉，企业微信，飞书
    def __str__(self):
        return self.label







